package com.fast.common.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title：统一返回结果
 * @author：ylc
 * @date：2018/7/18 17:16
 * @version：1.0
 **/
public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {
        put("code", 200);
        put("msg", "success");
        put("data", "");
    }

    public static R error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }
    public static R error(String msg) {
        R r = new R();
        r.put("code", 500);
        r.put("msg", msg);
        return r;
    }

    public static R ok(Object object) {
        R r = new R();
        r.put("data", object);
        return r;
    }

    public static R ok() {
        return new R();
    }

    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static R toMap(String key, Object value) {
        R r = new R();
        r.clear();
        r.put(key, value);
        return r;

    }
}
